#include "service.h"
#include "string-util.h"
int is_good_login(const char* username, const char* password, char* message, int max_message_length){
	int result;
	char conninfo[100];
	PGconn *conn;
	ustr_cpy(conninfo, max_message_length, "user=", username, " password=", password, " host=", HOST, " port=", PORT, NULL);
	conn = PQconnectdb(conninfo);
	result= (PQstatus(conn) == CONNECTION_OK);
	if (result){
		ustr_cpy(message, max_message_length, "Login success", NULL);
	} else {
		ustr_cpy(message, max_message_length, "Failed. ", PQerrorMessage(conn), NULL);
	}
	PQfinish(conn);
	return result;
}
